/**
 * @param {number[]} nums
 * @param {number} p
 * @return {number}
 */
var minSubarray = function (nums, p) {
  let left = 0,
    max = 0
  while (left < nums.length) {
    for (let right = left + 1; right <= nums.length; right++) {
      if (nums.slice(left, right).reduce((pre, cur) => pre + cur) % p == 0) {
        max = Math.max(max, right - left )
      }
    }
    left++
  }

  return nums.length - max
}

minSubarray([1,2,3], 3)
